//
//  RightTableViewCell.m
//  Linkage
//
//  Created by LeeJay on 16/8/22.
//  Copyright © 2016年 LeeJay. All rights reserved.
//

#import "HECategGoodsCell.h"

@interface HECategGoodsCell ()

@property (nonatomic, strong) UIImageView *goodsimgView;
@property (nonatomic, strong) UIImageView *selectBtn;
@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UILabel *priceLb;
@property (nonatomic, strong) UILabel *skuLb;
@property (nonatomic, strong) UILabel *oldPriceLb;
@end

@implementation HECategGoodsCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
 
        [self initUI];
    }
    return self;;
}

- (void)initUI {


    UIView *warp = [UIView new];
    warp.backgroundColor = KWhiteColor;
    [self.contentView addSubview:warp];

    [warp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(1);
        make.left.equalTo(self.contentView);
        make.right.equalTo(self.contentView);
        make.height.mas_greaterThanOrEqualTo(105);
        make.bottom.equalTo(self.contentView).mas_offset(-1);
    }];

 
    // 商品图片
    _goodsimgView = [UIImageView new];
    _goodsimgView.contentMode = UIViewContentModeScaleAspectFill;
    [warp addSubview:_goodsimgView];
    _goodsimgView.layer.masksToBounds = YES;
    _goodsimgView.layer.cornerRadius = 6.0;
    
    // 商品名称
    _titleLb = [UILabel new];
    _titleLb.text = @"";
    _titleLb.font = DYFont(16);
    [warp addSubview:_titleLb];
    
    // 规格
    _skuLb = [UILabel new];
    _skuLb.text = @"规格：";
    _skuLb.font = DYFont(14);
    _skuLb.numberOfLines = 2;
    _skuLb.textColor = UIColor.lightGrayColor;
    [warp addSubview:_skuLb];
    
//    _skuLb.p
    
    // 价格
    _priceLb = [UILabel new];
    _priceLb.text = @"￥0.00";
    _priceLb.font = DYBlodFont(16);
    _priceLb.textColor = KHexColor(@"#FF5757");
    [warp addSubview:_priceLb];
    
    // 价格
    _oldPriceLb = [UILabel new];
    _oldPriceLb.text = @"￥0.00";
    _oldPriceLb.font = DYFont(14);
    _oldPriceLb.textColor = KHexColor(@"#AAAAAA");
    [warp addSubview:_oldPriceLb];
       
    [_goodsimgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(warp);
        make.left.equalTo(warp).mas_offset(15);
        make.width.height.mas_offset(70);
    }];

    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).mas_offset(10);
        make.left.equalTo(_goodsimgView.mas_right).mas_offset(15);
        make.right.equalTo(warp.mas_right).mas_offset(-15);
    }];
    
    [_skuLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(5);
        make.left.equalTo(_titleLb.mas_left);
        make.right.equalTo(warp).mas_offset(-15);
    }];
    
    [_priceLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_skuLb.mas_bottom).mas_offset(10);
        make.left.equalTo(_titleLb.mas_left);
    }];
    [_priceLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    [_oldPriceLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_priceLb.mas_bottom);
        make.left.equalTo(_priceLb.mas_right).mas_offset(6);
        make.right.equalTo(self.contentView).mas_offset(10);
    }];
}

- (void)setModel:(HEGoodsModel *)model {
    
    _model = model;
    _titleLb.text = model.name;
    [_goodsimgView sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:IMAGE_NAMED(@"noImage")];
    _skuLb.text = model.desc;
    _priceLb.text = [NSString stringWithFormat:@"￥%@", model.Kprice];

    //中划线
    // 赋值
    _oldPriceLb.attributedText = model.KOrangeprice;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
